<template>
  <div class="login-container">
    <div class="background-animation"></div>
    <el-card class="login-card">
      <h2 class="login-title">欢迎登录</h2>
      <el-form :model="loginForm" label-width="80px" class="login-form">
        <el-form-item label="用户名">
          <el-input 
          id="username"
            v-model="loginForm.username" 
            placeholder="请输入用户名"
            class="custom-input">
            <template #prefix>
              <el-icon><User /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input 
          id="password"
            v-model="loginForm.password" 
            type="password" 
            placeholder="请输入密码"
            class="custom-input">
            <template #prefix>
              <el-icon><Lock /></el-icon>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button 
            type="primary" 
            @click="handleLogin"
            class="login-button"
            id="loginBtn">
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { reactive } from 'vue';
import { useRouter } from'vue-router'
import {useCounterStore} from '../stores/user'
import axios from 'axios';
import { User, Lock } from '@element-plus/icons-vue'

const router = useRouter()
let UserData= useCounterStore()
const loginForm = reactive({
  username: '',
  password: ''
});

const handleLogin = async() => {
//   // 掉接口，获取登录信息
// //页面级别的权限管理【角色控制] 按钮级别的权限管理[权限控制]
// const data={
//     username:'admin',
//     password:'123456',
//     rolename:['teacher'],
//     auths:['deltee','add']
// }
// //全局数据，使用状态管理器 【vuex,pinia】
// localStorage.setItem('userLogin',JSON .stringify(data))




  console.log('登录信息:', loginForm);
  let {data:{code,sj}}=await axios.post('http://localhost:3000/getUser',loginForm)
  console.log(code);
  
  if(code==200){
     UserData.setUserData(sj)
     console.log(sj,'22');
      // 等待路由更新
      await new Promise(resolve => setTimeout(resolve, 100));

     router.push('/index')
     console.log('pinia',UserData.userdata.value);
     

  }
};
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

.background-animation {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
  background-size: 400% 400%;
  animation: gradient 15s ease infinite;
  z-index: -1;
}

@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.login-card {
  width: 400px;
  padding: 30px;
  border-radius: 15px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.9);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.login-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 25px rgba(0, 0, 0, 0.15);
}

.login-title {
  text-align: center;
  color: #333;
  margin-bottom: 30px;
  font-size: 28px;
  font-weight: 600;
}

.login-form {
  margin-top: 20px;
}

.custom-input :deep(.el-input__wrapper) {
  border-radius: 8px;
  transition: all 0.3s ease;
}

.custom-input :deep(.el-input__wrapper:hover) {
  box-shadow: 0 0 0 1px #409EFF;
}

.custom-input :deep(.el-input__wrapper.is-focus) {
  box-shadow: 0 0 0 1px #409EFF;
}

.login-button {
  width: 100%;
  height: 40px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.3s ease;
  background: linear-gradient(45deg, #409EFF, #36D1DC);
  border: none;
}

.login-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(64, 158, 255, 0.3);
}

.login-button:active {
  transform: translateY(0);
}

:deep(.el-form-item__label) {
  font-weight: 500;
  color: #333;
}
</style> 